/*
 * @Author: your name
 * @Date: 2021-01-06 11:41:34
 * @LastEditTime: 2021-01-23 22:49:38
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \express-seed\dao\imgDao.js
 */
const { querySql } = require('../db')
module.exports = {
    // 查询销售列表
    getSellerDao: async (page_id) => {
        const sql = page_id ?`select * from sell_code where page_id='${page_id}'` : `select * from sell_code`
        return await querySql(sql)
    },
    //获取启用状态销售列表
    getSellerbyStartDao: async (page_id) => {
        const sql = page_id ? `select img_path,id,ad_person_name,page_id from sell_code where is_start='1'and page_id='${page_id}'` : `select img_path,id,ad_person_name,page_id from sell_code where is_start='1'`
        return await querySql(sql)
    },
    //添加销售
    addCodeDao: async (codeInfo) => {
        let insertStr = `('${codeInfo.imgsInfo[0].name}','${codeInfo.imgsInfo[0].imgPath}' ,'${codeInfo.ad_person_name}','${codeInfo.is_start}','${codeInfo.comment}','${codeInfo.page_id}')`
        let sql = `insert into sell_code (img_name, img_path , ad_person_name , is_start ,comment , page_id) values ` + insertStr
        return await querySql(sql)
    },
    //根据id删除销售
    delSellerDao: async (img_id) => {
        const sql = `delete from sell_code where id='${img_id}'`
        return await querySql(sql)
    },
    //修改用户状态
    updateSellerDao: async (sellerInfo) => {
        const sql = `update sell_code set is_start='${sellerInfo.is_start}' where id='${sellerInfo.id}'`
        return await querySql(sql)
    },
}
